from SecPlugin import *

plugin = Plugin(
    ws_url="ws://127.0.0.1:24804",
    pid="com.plugin.secplugin",
    name="SecPlugin",
    token="SecretToken",
    max_workers=4
)

@plugin.onCmd(Cmd.SyncOicq)
def onSyncOicq(msg: dict):
    plugin.log(f"SyncOicq {msg}")

@plugin.onHeartbeat()
def onHeartbeat(msg: dict):
    plugin.log(msg)

@plugin.onMsg("测试")
def test(messenger: 'Messenger'):
    plugin.sendMsg(messenger, 
                   f"bot账号：{messenger.get(Msg.Account)}\n",
                   f"bot总发言次数：{plugin.getTotalSend(messenger) + 1}\n",
                   f"bot本聊天发言次数：{plugin.getSend(messenger) + 1}\n",
                   f"bot总接收次数：{plugin.getTotalRecv(messenger)}\n",
                   f"bot本聊天接收次数：{plugin.getRecv(messenger)}"
    )

@plugin.onMsg(r"\s*(@[\s\S]*)+撤回\s*")
def onWithdrawSelfMsg(messenger: 'Messenger'):
    isOp = plugin.isOperator(messenger, uin=messenger.get(Msg.Account))
    if isOp or messenger.getList(Msg.AtUin)[0] == messenger.get(Msg.Account):
        plugin.withdraw(messenger, messenger.get(Msg.Reply))

@plugin.onWithdraw()
def onWithdraw(messenger: 'Messenger'):
    if messenger.get(Msg.Uin) != messenger.get(Msg.Account):
        plugin.sendMsg(messenger, "撤回监听")

plugin.start()